package com.payne;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.UUID;

public class UrlTest {
    public static void main(String[] args) {
        try {
            URL url = new URL("https://desk-fd.zol-img.com.cn/t_s960x600c5/g4/M01/04/09/Cg-4y1TthaKILoSaACCX4-br1qAAAVgtQHS6Z0AIJf7476.jpg");
            URLConnection con = url.openConnection();
            InputStream inStream = con.getInputStream();
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            byte[] buf = new byte[1024];
            int len = 0;
            while((len = inStream.read(buf)) != -1){
                outStream.write(buf,0,len);
            }
            inStream.close();
            outStream.close();
            String uuid = UUID.randomUUID().toString();
            File file = new File("f://test//"+uuid+".jpg");	//图片下载地址
            FileOutputStream op = new FileOutputStream(file);
            op.write(outStream.toByteArray());
            op.close();
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }



}
